// 定义结构体
pub struct Student {
    pub name: String,
    pub age: u32,
}

pub struct Teacher {
    pub name: String,
    pub age: u32,
// pub subject: String,
}

// 定义 trait
pub trait GetInfomation {
    fn get_name(&self) -> &String;
    fn get_age(&self) -> u32;
}

trait SchoolName {
    fn get_school_name(&self) -> String {
        return String::from("红星学校");
    }
}

// 实现 trait
impl GetInfomation for Student {
    fn get_name(&self) -> &String {
        return &self.name;
    }
    fn get_age(&self) -> u32 {
        return *&self.age;
    }
}

impl GetInfomation for Teacher {
    fn get_name(&self) -> &String {
        return &self.name;
    }
    fn get_age(&self) -> u32 {
        return *&self.age;
    }
}

impl SchoolName for Student {}

fn main() {
    let mut student = Student {
        name: String::from("小明"),
        age: 10,
    };

    let mut teacher = Student {
        name: String::from("张老师"),
        age: 20,
    };
    println!("学生,name={},age={}", student.get_name(), student.get_age());
    println!("老师,name={},age={}", teacher.get_name(), teacher.get_age());
    let studentSchoolName = student.get_school_name();
    let teacherSchoolName = teacher.get_school_name();

    // 默认实现
    println!("{}", studentSchoolName);
    println!("{}", teacherSchoolName);
}
